﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class morning_delitem : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Request["ids"];
        string tbName = Request["table"];
        if (string.IsNullOrEmpty(id))
        {
            this.ClientScript.RegisterStartupScript(GetType(), "initerror", "<script>alert('必须有相对应的个股才能编辑.');CloesPage();</script>");
        }
        else
        {
            string[] ids = id.Split(new char[] { ',' });

            List<int> tids = new List<int>();
            foreach (string arg in ids)
            {
                int tag = 0;
                if (int.TryParse(arg, out tag))
                {
                    tids.Add(tag);
                }
            }

            WebsiteDataModel.WebsiteDataEntities de = new WebsiteDataModel.WebsiteDataEntities();
            //var re=null;
            switch (tbName)
            {
                case "ggrq":
                    var re1 = from a in de.XG_ggrq
                             where tids.Contains(a.id)
                             select a;
                    foreach (WebsiteDataModel.XG_ggrq node in re1)
                    {
                        de.XG_ggrq.DeleteObject(node);
                    }
                    break;
                case "invset":
                    var re2 = from a in de.XG_Invset
                             where tids.Contains(a.tid)
                             select a;
                    foreach (WebsiteDataModel.XG_Invset node in re2)
                    {
                        de.XG_Invset.DeleteObject(node);
                    }
                    break;
                case "partner":
                    var re3 = from a in de.XG_Partner
                              where tids.Contains(a.tid)
                              select a;
                    foreach (WebsiteDataModel.XG_Partner node in re3)
                    {
                        de.XG_Partner.DeleteObject(node);
                    }
                    break;
                default:
                    break;
            }
            
            int num = de.SaveChanges();
            if (num > 0)
            {
                this.ClientScript.RegisterStartupScript(GetType(), "initerror", "<script>alert('删除成功.');CloesPage();</script>");
            }
            else
            {
                this.ClientScript.RegisterStartupScript(GetType(), "initerror", "<script>alert('删除失败.');CloesPage();</script>");
            }
        }
    }
}